package gwc.Controller;

import com.mysql.cj.PreparedQuery;
import gwc.Business.SaleService;
import gwc.DAO.GwcDAO;
import gwc.Model.Gwc;
import gwc.Model.Users;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;

@Controller
public class GwcController {


    SaleService service;


//



//    @RequestMapping(value = "/index.html")
//    public String loginindex(){ return "loginindex"; }
//
//    @RequestMapping(value = "/logincheck.html")
//    public String logincheck(){ return "logincheck"; }
////登录失败页面
//    @RequestMapping(value = "/failure.html")
//    public String failure(){ return "failure"; }
    //主页面
    @RequestMapping(value = "/index.html")
    public String main(){ return "main";}
//主页面加入购物车
    @RequestMapping(value = "addgouwuche")
    public String addgouwuche(HttpServletRequest request,Gwc add){
        service.Gwcinsert(add);
        System.out.println("已成功添加"+add);
        return "main";
    }

//    @RequestMapping(value = "/index.html")
//    public String loginindex(){ return "loginindex"; }
//
//    @RequestMapping(value = "/logincheck.html")
//    public String logincheck(){ return "logincheck"; }
//登录失败页面
//    @RequestMapping(value = "/failure.html")
//    public String failure(){ return "failure"; }

//购物车表格内容页面
    @RequestMapping(value = "/gouwuche.html")
    public String gouwuchelist(HttpServletRequest request){
        request.getSession().setAttribute("gouwuches",service.GwcqueryAll());
        request.getSession().setAttribute("zongjia",service.zj());
        return "gouwuche";
    }
//购物车数量减
    @RequestMapping(value = "jian")
    public String jian(HttpServletRequest request,Gwc jian){
        service.jian(jian);
        System.out.println("已成功减"+jian);
        request.getSession().setAttribute("gouwuches",service.GwcqueryAll());
        request.getSession().setAttribute("zongjia",service.zj());
        return "gouwuche";
    }
//购物车数量加
    @RequestMapping(value = "jia")
    public String jia(HttpServletRequest request,Gwc jia){
        service.jia(jia);
        request.getSession().setAttribute("gouwuches",service.GwcqueryAll());
        request.getSession().setAttribute("zongjia",service.zj());
        return "gouwuche";
    }
//购物车删除某一物品
    @RequestMapping(value = "del")
    public String delgouwuche(HttpServletRequest request,Gwc del){
        service.Gwcdelete(del);
        System.out.println("已删除"+del);
        request.getSession().setAttribute("gouwuches",service.GwcqueryAll());
        request.getSession().setAttribute("zongjia",service.zj());
        return "gouwuche";
    }
//确认提交页面
    @RequestMapping(value = "/dingdan.html")
    public String dingdanlist(HttpServletRequest request,Gwc insert){
        request.getSession().setAttribute("gouwuches",(service.GwcqueryAll()));
        request.getSession().setAttribute("zongjia",service.zj());
        request.getSession().setAttribute("userss",service.UsersqueryAll());
        service.Dingdaninsert(insert);
        return "dingdan";
    }
//我的信息
    @RequestMapping(value = "/wodexinxi.html")
    public String wodexinxi(HttpServletRequest request){
        request.getSession().setAttribute("userss",service.UsersqueryAll());
        return "wodexinxi";
    }
//我的信息修改
    @RequestMapping(value = "xiugai")
    public String xiugaixinxi(HttpServletRequest request,Users users){
        service.Usersmodify(users);
        request.getSession().setAttribute("userss",service.UsersqueryAll());
        return "wodexinxi";
    }
//我的订单
    @RequestMapping(value = "/wodedingdan.html")
    public String wodedingdan(HttpServletRequest request){
        request.getSession().setAttribute("dingdans",service.DingdanqueryAll());
        return "wodedingdan";
    }

    @Autowired
    public void setService(SaleService service) {
        this.service = service;
    }
}

